<?php
Yii::app()->clientScript->registerScript('search', "
$('#search-button').toggle(function(){
	$('.search-form').toggle('slow');
	$(this).attr('title','Masquer le formulaire de recherche');
	$('#search-button').tooltip('destroy');
	$('#search-button').tooltip();
	$('#search_angle').removeClass('fa-angle-right').addClass('fa-angle-down');
	return false;
}, function(){
	$('.search-form').toggle('slow');
	$(this).attr('title','Afficher le formulaire de recherche');
	$('#search-button').tooltip('destroy');
	$('#search-button').tooltip();
	$('#search_angle').removeClass('fa-angle-down').addClass('fa-angle-right');
	return false;
});
$('#init-button').click(function(){
	$(':input','.search-form form')
		.not(':button, :submit, :reset, :hidden')
		.val('')
		.removeAttr('checked')
		.removeAttr('selected');
	$('select option:selected').removeAttr('selected');
	$('#seliste-grid').yiiGridView('update', {
		data: '',
		url: '" . ($liste ? Yii::app()->createUrl('seliste/liste') : Yii::app()->createUrl('seliste/admin')) . "'
	});
	return false;
});
$('.search-form form').submit(function(){
	$('#seliste-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
$('#search-button').tooltip();
$('#add-button').tooltip();
");
?>


<div class="container">
	
	<?php if(Yii::app()->user->hasFlash('seliste')) {?>
	<div class="row">
		<div class="col-lg-12">
			<div class="alert alert-success alert-dismissable">
				<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
				<?php echo Yii::app()->user->getFlash('seliste'); ?>
				<?php
				Yii::app()->clientScript->registerScript('close-alert', "
					window.setTimeout(function() { $('.alert').alert('close'); }, 4000);
				");
				?>
			</div>
		</div>
	</div>
	<?php } ?>
	
	<div class="row">
		<div class="col-lg-12">		
			<div class="page-header">	
				<h1>Liste des sélistes
					<div class="btn-group" id="seliste_toolbar">
					<?php 
					if ($this->route == "seliste/admin") echo CHtml::link("<span class=\"fa fa-plus\"></span>",array("seliste/create"),array("id"=>"add-button",'class'=>"btn btn-info","data-toggle"=>"tooltip","data-placement"=>"top","title"=>"Ajouter un séliste","data-container"=>"body"));
					echo CHtml::link("<span class=\"fa fa-search\"></span> <span id=\"search_angle\" class=\"fa fa-angle-right\"></span>",'#',array("id"=>"search-button",'class'=>"btn btn-info","data-toggle"=>"tooltip","data-placement"=>"top","title"=>"Afficher le formulaire de recherche","data-container"=>"body"));
					?>
					</div>
				</h1>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<div class="search-form" style="display:none">
			<?php $this->renderPartial('_search',array(
				'model'=>$model
			)); ?>
			</div><!-- search-form -->

			<?php $this->widget('ext.bs3gridview.widgets.Bs3GridView', array(
				'id'=>'seliste-grid',
				'dataProvider'=>$model->search(),
				'rowCssClass' => array('pointer'),
				'selectableRows'=>1,
				'selectionChanged'=>'function(id){ location.href = "'.$this->createUrl('seliste/view').'&id="+$.fn.yiiGridView.getSelection(id);}',
				'columns'=>array(
					'id',
					array(
							'name'=>'nom',
							'type'=>'html',
							'value'=>'($data->v_nom == 1 || Yii::app()->user->id == $data->id || Yii::app()->user->admin) ? $data->nom : "<span class=\"fa fa-eye-slash\"></span>"'
					),
					array(
							'name'=>'prenom',
							'type'=>'html',
							'value'=>'($data->v_prenom == 1 || Yii::app()->user->id == $data->id || Yii::app()->user->admin) ? $data->prenom : "<span class=\"fa fa-eye-slash\"></span>"'
					),
					array(
							'name'=>'pseudo',
							'type'=>'html',
							'value'=>'($data->v_pseudo == 1 || Yii::app()->user->id == $data->id || Yii::app()->user->admin) ? $data->pseudo : "<span class=\"fa fa-eye-slash\"></span>"'
					),						
					array(
							'name'=>'ville',
							'type'=>'html',
							'value'=>'($data->v_ville == 1 || Yii::app()->user->id == $data->id || Yii::app()->user->admin) ? $data->ville : "<span class=\"fa fa-eye-slash\"></span>"'
					),
					array(
							'name'=>'date_inscr',
							'visible'=>Yii::app()->user->admin,
							'value'=>'Yii::app()->dateFormatter->format(\'dd/MM/yyyy\',$data->date_inscr)',
					),
					array(
						'class'=>'CButtonColumn',
						'header'=>'Actions',
						'htmlOptions'=>array('width'=>'100px'),
						'template' => '{view} {update} {update_grains} {update_pass} {delete}',
						'viewButtonImageUrl' => false,
						'updateButtonImageUrl' => false, 
						'deleteButtonImageUrl' => false, 
						'buttons'=>array(
									'view'=>array(
											'label'=>"",
											'options'=>array(
													"class"=>"glyphicon glyphicon-search",
													"title"=>"Voir"
											),
									),
									'update_pass'=>array(
											'label'=>"",
											'url'=>'Yii::app()->createUrl(\'seliste/update_pass\',array(\'id\'=>$data->id))',
											'options'=>array(
												"class"=>"glyphicon glyphicon-lock",
												"title"=>"Changer le mot de passe"
												),
											'visible'=>'(!$data->admin && Yii::app()->user->admin) || Yii::app()->user->admin',
										),  
									'update_grains'=>array(
											'label'=>"",
											'url'=>'Yii::app()->createUrl(\'seliste/update_grains\',array(\'id\'=>$data->id))',
											'options'=>array(
												"class"=>"glyphicon glyphicon-list",
												"title"=>"Liste des grains"
												),
											'visible'=>'(!$data->admin && Yii::app()->user->admin) || Yii::app()->user->admin',
										),  
									'update'=>array(
											'label'=>"",
											'options'=>array(
												"class"=>"glyphicon glyphicon-edit",
												"title"=>"Mettre à jour"
												),
											'visible'=>'(!$data->admin && Yii::app()->user->admin) || Yii::app()->user->admin',
										),
									'delete'=>array(
											'label'=>"",
											'options'=>array(
												"class"=>"glyphicon glyphicon-remove",
												"title"=>"Supprimer"
												),
											'visible'=>'((!$data->admin && Yii::app()->user->admin) || Yii::app()->user->admin) && ($data->id<>Yii::app()->user->id)',
										),  
									),  
					),
				),
			)); ?>
		</div>
	</div>
</div>